package com.example.k8s.hello.service.sys.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.k8s.hello.common.bean.Page;
import com.example.k8s.hello.service.sys.dao.SysLogDao;
import com.example.k8s.hello.service.sys.service.SysLogService;
import org.apache.commons.lang3.StringUtils;
import com.example.k8s.hello.bean.sys.entity.SysLogEntity;
import com.example.k8s.hello.bean.sys.query.SysLogQuery;
import org.springframework.stereotype.Service;


@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogDao, SysLogEntity> implements SysLogService {

    @Override
    public Page queryPage(SysLogQuery query, Page page) {
        String key = query.getKey();

        return this.page(
                page,
                Wrappers.lambdaQuery(SysLogEntity.class).and(StringUtils.isNotBlank(key), q ->
                        q.like(SysLogEntity::getUsername, key)
                        .or()
                        .like(SysLogEntity::getOperation, key)
                ).orderByDesc(SysLogEntity::getCreateTime)

        );
    }
}
